package org.robot.scm.utils;

import java.util.Date;
import org.apache.commons.lang3.StringUtils;

/**
 * 短链
 *
 * @Author : Awn create on 2024/6/20 09:17
 */
public class ShortLinkUtil {

    private static final String KEY = "65ea41ab121fd2e9f7d946a83caea@f8e8ac27f8f692d48f16303274bdfee5";

    public static String link(String url, String domain, int expireHours) {
        String expireDate = DateTool.format(new Date().getTime() + (long) expireHours * 3600 * 1000, DateTool.PATTERN_1);
        String sUrl = String.format("http://api.suolink.cn/api?url=%s&key=%s&domain=%s&expireDate=%s", url, KEY, domain, expireDate);
        String sUrlResult = RequestHelper.get(sUrl);
        if (!StringUtils.isBlank(sUrlResult)) {
            return sUrlResult;
        }
        return url;
    }

}
